#include "entityfactory.h"
#include "../entities/unoboardentity.h"
#include "../entities/whiteledentity.h"
#include "../entities/groundentity.h"
#include "../entities/connectorentity.h"
#include "../entities/elements/dt2821b.h"
#include "../entities/elements/dt2821a.h"
#include "../entities/logicChips/chip74ls138.h"
#include "../entities/logicChips/chip74lcx157d.h"

Entity *Aurasim::newEntity(const QString &name)
{
    Entity* e = nullptr;
    if (name == "Ground")
        e = new GroundEntity;

    if (name == "WhiteLed")
        e = new WhiteLedEntity;

    if (name == "UnoBoard")
        e = new UnoBoardEntity;

    if (name == "DT2821B")
        e = new DT2821B;

    if (name == "DT2821A")
        return new DT2821A;

    if (name == "74Ls138")
        return new Chip74LS138;

    if (name == "74LCX157-D")
        return new Chip74LCX157D;

    return e;
}

QJsonObject Aurasim::toJsonObject(Entity *e)
{
    if(e->name() == "Connector") {
        ConnectorEntity* connector = static_cast<ConnectorEntity*>(e);
        return connector->toJsonObject();
    }

    return e->toJsonObject();
}
